import yagmail
import random
import string

from Config.email_conf import user, authcode, host

mail = yagmail.SMTP(user=user, password=authcode, host=host)


def code_generator(size=6):
    # 生成6位字母数字混合验证码
    characters = string.ascii_letters + string.digits
    verification_code = ''.join(random.choice(characters) for _ in range(size))
    return verification_code


def send_code(tar):
    subject = '来自易投的验证码'
    content = f'验证码为:{code_generator(6)}'
    mail.send(to=tar, subject=subject, contents=content)
